
function text1(){
    return new Promise((resolve, reject) => {
        setTimeout(function () {
            resolve('1111111111');//返回写函数里面你要执行的内容
        },3000)

    })

}
function text2(data){
    return new Promise((resolve, reject) =>{
            console.log(data)
            let res=data+'22222222'
            setTimeout(()=>{
                resolve(res);
            },3000)
        }
    )
}
function text3(data){
    return Promise.resolve(()=>{
        // console.log(tempList)
        // return mergeData(newList,tempList);
        return "+++1+++";
    })
}
// console.log(text3());

function timeFN1(){
    let res='';
    return Promise.resolve(text1().then((data) => {
            //这是内层then函数begin
            text2(data).then((data)=>{
                return data;
                // return '789465'     //返回undefined
            })
            //这是内层then函数end
            return res      //返回的数据时外层的then函数
        })
    )
}
function timeFN2(){
    let res='';
    return Promise.resolve(text1().then((data) => {
            //这是内层then函数begin
            return text2(data).then((data)=>{
                    console.log(data);
                    return data+'3333333';
                // return '789465'     //返回undefined
            })
        })
    )
}

/**
 * return Promise.resolve与return new Promise
 * 两者存在的区别是：前者直接返回setTimeout没有等待
 * 后者使用resolve能等待接口返回数据再往下走
 * @returns 
 */
function timeFN3(){
    return Promise.resolve(text1().then(async (data) => {
            //这是内层then函数begin
            const data_2 = await text2(data);
            console.log(data_2);
            setTimeout(()=>{
                return data_2 + '3333333';
            },3000)
        })
    )
}

function timeFN(){
    return new Promise((resolve,reject)=>{
        text1().then(async (data) => {
            //这是内层then函数begin
            const data_2 = await text2(data);
            console.log(data_2);
            setTimeout(()=>{
                resolve(data_2 + '3333333');
            },3000)
        })
    })
}

timeFN().then((data)=>{
    console.log(data,'res')
})
